{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 本周内容"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i\n",
      "i\n",
      "a\n"
     ]
    }
   ],
   "source": [
    "vowels = [\"a\",\"e\",\"i\",\"o\",\"u\"]\n",
    "word = \"milliways\"\n",
    "# for letter in word:  # 检查word中出现的元音，并打印出来\n",
    "#第一个元素letter请不要和已有的变量重名\n",
    "# 第一个元素一般不命名，常用item（元素）来命名简写i\n",
    "# 第二个元素word（重要），意味着将遍历的内容\n",
    "# 遍历的内容一般是序列数据str /list\n",
    "for letter in word:\n",
    "    if letter in vowels: \n",
    "        print(letter)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 使用append（）新建列表\n",
    "vowels = [\"a\",\"e\",\"i\",\"o\",\"u\"]\n",
    "word = \"milliways\"\n",
    "found = []\n",
    "for letter in word:\n",
    "    if letter in vowels:# letter在元音字母表中\n",
    "        if letter not in found:# letter 不在found表中\n",
    "            found.append(letter)\n",
    "for vowels in found:\n",
    "        print(vowels)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##  购物车"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "* 1、运行程序后，让用户输入支付宝余额，然后打印我们的商品列表给用户。\n",
    "\n",
    "* 2、让用户输入商品编号进行商品的购买。\n",
    "\n",
    "* 3、用户选择商品后，检查用户的余额是否够，若够则直接扣款，不够则提醒用户。\n",
    "\n",
    "* 4、用户可以随时退出购买，推出时打印用户已购买的商品和支付宝余额。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 每个商品的内容是多个值的值，可选用list\n",
    "products = [[\"纸巾\", 5], [\"糖果\", 10], [\"奶茶\", 20], [\"口红\", 350]]\n",
    "# 用户购物信息数据存放\n",
    "shopping_list = []\n",
    "# 用户输入余额信息\n",
    "balance = int(input(\"请输入您的账户余额：\"))\n",
    "# 打印商品信息\n",
    "# info = ''' ------------- good list ---------------\n",
    "# 商品编号： %s, 商品名称：%s, 商品价格：%s\n",
    "# 商品编号： %s, 商品名称：%s, 商品价格：%s\n",
    "# 商品编号： %s, 商品名称：%s, 商品价格：%s\n",
    "# 商品编号： %s, 商品名称：%s, 商品价格：%s\n",
    "# '''%(0,products[0][0],products[0][1],\n",
    "#      1,products[1][0],products[1][1],\n",
    "#      0,products[2][0],products[2][1],\n",
    "#      0,products[3][0],products[3][1],)\n",
    "# print(info)\n",
    "# list的长度？ len（）\n",
    "\n",
    "# 执行循环\n",
    "\n",
    "while True:\n",
    "    print('------------- good list ---------------')\n",
    "    for i in range(len(products)):\n",
    "        print(\"商品编号： %s, 商品名称：%s, 商品价格：%s元\" % (i, products[i][0], products[i][1]))\n",
    "    # 用户输入商品编号，实现查询\n",
    "    choice = input(\"请输入商品编号:\")  # input 输入的内容默认是字符串str，例如输入2，则显示“2”\n",
    "    if choice.isdigit():\n",
    "        # 判断编号是否存在\n",
    "        if int(choice) < len(products):\n",
    "            # 检查用户余额 > 商品价格\n",
    "            if balance > products[int(choice)][1]:\n",
    "                balance = balance - products[int(choice)][1]  # 用户余额发生变化，要扣除\n",
    "                shopping_list.append(products[int(choice)])\n",
    "                pass\n",
    "            else:\n",
    "                print(\"您的余额已不足，请更换其他支付方式\")\n",
    "            pass\n",
    "        else:\n",
    "            print(\"请输入正确的商品编号，您输入的商品不存在\")\n",
    "    elif choice == \"退出\":\n",
    "     # 打印用户余额和用户的商品列表信息\n",
    "     print(\"用户余额：%s,购物车：%s\" % (balance, shopping_list))\n",
    "     break\n",
    "    # for i in products:\n",
    "    #     print(\"编码：\",products.index(i),i)\n",
    "\n",
    "# shoppingcar = input(\"请输入选购商品的编码，加入购物车：\")\n",
    "# shopping_list.append()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
